<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-mpFinancialSetting-edit" th:object="${mpFinancialSetting}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
			<div class="form-group">	
				<label class="col-sm-3 control-label">提款密码：</label>
				<div class="col-sm-8">
					<input id="withdrawalPassword" name="withdrawalPassword" th:field="*{withdrawalPassword}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">谷歌校验密钥：</label>
				<div class="col-sm-8">
					<input id="googleSecret" name="googleSecret" class="form-control" type="text" readonly>
					<a onclick="resetGoogleSecret()" href="javascript:void(0);" class="btn btn-info btn-xs" style="margin-left: 100%;margin-top: -9%"><i class="fa fa-refresh"></i>重置</a>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">代付规则：</label>
				<div class="col-sm-8">
					<select id="mchWithdrawalRule" name="mchWithdrawalRule" class="form-control" >
						<option value="1">渠道优先级</option>
						<option value="2">渠道余额大小</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">代付内扣：</label>
				<div class="col-sm-8">
					<select class="form-control" id="withdrawalInner" name="withdrawalInner">
						<option value="0">是</option>
						<option value="1">否</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">代付审核：</label>
				<div class="col-sm-8">
					<select class="form-control" id="withdrawalAudit" name="withdrawalAudit">
						<option value="0">是</option>
						<option value="1">否</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">渠道ip白名单：</label>
				<div class="col-sm-8">
					<select class="form-control" id="channelWhite" name="channelWhite">
						<option value="0">是</option>
						<option value="1">否</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">商户ip白名单：</label>
				<div class="col-sm-8">
					<select class="form-control" id="merchantWhite" name="merchantWhite">
						<option value="0">是</option>
						<option value="1">否</option>
					</select>
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script th:inline="javascript">
		var mpFinancialSetting = [[${mpFinancialSetting}]];
		var $form = $("#form-mpFinancialSetting-edit");
		// 谷歌秘钥赋值
        $form.find("input[name='googleSecret']").val(mpFinancialSetting.googleSecret);
		// 代付内扣
        $form.find("select[name='withdrawalInner']").find("option[value=" + mpFinancialSetting.withdrawalInner + "]").attr("selected","selected");
        // 代付审核
        $form.find("select[name='withdrawalAudit']").find("option[value=" + mpFinancialSetting.withdrawalAudit + "]").attr("selected","selected");
        // 渠道ip白名单
        $form.find("select[name='channelWhite']").find("option[value=" + mpFinancialSetting.channelWhite + "]").attr("selected","selected");
        // 商户ip白名单
        $form.find("select[name='merchantWhite']").find("option[value=" + mpFinancialSetting.merchantWhite + "]").attr("selected","selected");

		var prefix = ctx + "financial/mpFinancialSetting";
        $form.validate({
			rules:{
				withdrawalPassword:{
					required:true,
				},
			},
			focusCleanup: true
		});

        /**
         * 谷歌秘钥重置
         */
        function resetGoogleSecret() {
            $.post(prefix + "/resetCode",{},function (response) {
                var newCode = response;
                $form.find("input[name='googleSecret']").val(newCode);
            });
        }


		function submitHandler() {
	        if ($.validate.form()) {
                var data = $('#form-mpFinancialSetting-edit').serializeArray();
                console.info(data);
	            $.operate.save(prefix + "/edit", data);
	        }
	    }

		$(function () {
			// 数据回显
			var a = mpFinancialSetting.mchWithdrawalRule;
			$("#mchWithdrawalRule option[value="+a+"]").attr("selected","selected");
		})
	</script>
</body>
</html>
